const NinelineModel = require("../model/NinelineModel")
const redis = require("../utils/redis")

redis.init({
  host : "123.57.129.108",
  port : "6379",
  password:"ARspjl9tQFIfI",
})
async function main(){
    let model = new NinelineModel();
    // model.calImageLv();
    // return;
    let result = await model.startGame(1001,9)
    console.log(JSON.stringify(result))
    return;
    // let totalWins = 0,count = 0, multipleList = {};
    let totalBetAmount = 0, totalWins =0, winCount = 0,totalFreeCount = 0,totalFreeWin =0;
    let betAmount = 9;
    for(let i = 0; i < 1000000; i++){
        // console.log(i)
        if(i%10000==0){
          console.log(i)
        }
        let data = await model.startGame(1002, betAmount)
        let result = data.result;
        let {wins, free} = result
        let {lineScore, jackpotScore} = wins
        if(lineScore+jackpotScore> 0 || free){
          winCount ++;
          totalWins += lineScore+jackpotScore
        }
        if(!free){
          totalBetAmount += 9;
        }else{
          totalFreeCount ++;
          totalFreeWin += lineScore+jackpotScore
        }
            // totalWins+= multiplier;
            // count++
            // multipleList[multiplier] = multipleList[multiplier] || 0;
            // multipleList[multiplier] ++;
    }
    console.log("-------------100万局结果-------------------")
    console.log("总消耗：", totalBetAmount, " 总盈利:"+ totalWins, " 盈利局数:"+ winCount," 非免费游戏局数:")
    console.log("免费局数:", totalFreeCount, " 免费盈利:" + totalFreeWin)
}

async function test(){
  try{

    let model = new NinelineModel();
    // let lineResults = [
    //   { line: 1, image: 4, count: 4, multiplier: 60 },
    //   { line: 8, image: 6, count: 3, multiplier: 20 }
    // ]
    // let [views, winLineResults] = model.fillWinViews(lineResults) //填充赢的视图
    for(let i = 0; i< 1000; i++){
      console.log('111111111111111111111111111111')
      let result = await model.calPlayerViewAndResult(1)
      console.log('22222222222222222222222222222222')
      if(result.length>2){
        break;
      }
    }
    
  }catch(err){
    console.log(err)
  }
  
}
async function notWinTest(){
  try{
    let model = new NinelineModel();
    for(let i = 0; i< 10000; i++){
      let views = [ [ -1, -1, 1000, -1, -1 ], [ 6, 4, -1, 4, -1 ], [ 4, 6, 6, 5, 12 ] ]
      model.fillAllImage(views, [])
      model.views = views;
      let result = model.calResult()
      if(result.length >2){
        console.log(views)
        console.log(result)
        break;
      }
    }
    console.log("success")
    
  }catch(err){
    console.log(err)
  }
}



function test1(){
  try{
    let model = new NinelineModel();
    let views = [[7,1,1000,8,-1],[6,4,9,4,4],[4,6,6,5,12]]
    let notImage = model.getNotShowImage(views, [0,4])
    console.log(notImage)
  }catch(err){
    throw err;
  }
}

function test2(){
  try{
    let model = new NinelineModel();
    let views = [[7,-1,-1,-1,-1],[1,12,7,6,1],[-1,-1,-1,-1,-1]] 
    let notImages = [7,1000,1];
    let positions = [0,1]
    model.fillPositionImage(views, positions, model.imageOdds, notImages)
  }catch(err){
    throw err;
  }
}

// main();
// test();
notWinTest();
// test1()
// test2();

return;
const multiplierSuccessLines = [
    { image: 1, multiplier: 60, count: 3, lv: 0.000043209876543209875 },
    { image: 1, multiplier: 150, count: 4, lv: 0.00001728395061728395 },
    { image: 1, multiplier: 600, count: 5, lv: 0.0000043209876543209875 },
    { image: 2, multiplier: 50, count: 3, lv: 0.00005185185185185184 },
    { image: 2, multiplier: 100, count: 4, lv: 0.00002592592592592592 },
    { image: 2, multiplier: 300, count: 5, lv: 0.000008641975308641975 },
    { image: 3, multiplier: 40, count: 3, lv: 0.0000648148148148148 },
    { image: 3, multiplier: 80, count: 4, lv: 0.0000324074074074074 },
    { image: 3, multiplier: 200, count: 5, lv: 0.00001296296296296296 },
    { image: 4, multiplier: 30, count: 3, lv: 0.00008641975308641975 },
    { image: 4, multiplier: 60, count: 4, lv: 0.000043209876543209875 },
    { image: 4, multiplier: 1500, count: 5, lv: 0.000001728395061728395 },
    { image: 5, multiplier: 25, count: 3, lv: 0.00010370370370370369 },
    { image: 5, multiplier: 50, count: 4, lv: 0.00005185185185185184 },
    { image: 5, multiplier: 100, count: 5, lv: 0.00002592592592592592 },
    { image: 6, multiplier: 20, count: 3, lv: 0.0001296296296296296 },
    { image: 6, multiplier: 40, count: 4, lv: 0.0000648148148148148 },
    { image: 6, multiplier: 80, count: 5, lv: 0.0000324074074074074 },
    { image: 7, multiplier: 15, count: 3, lv: 0.0001728395061728395 },
    { image: 7, multiplier: 30, count: 4, lv: 0.00008641975308641975 },
    { image: 7, multiplier: 60, count: 5, lv: 0.000043209876543209875 },
    { image: 8, multiplier: 10, count: 3, lv: 0.0002592592592592592 },
    { image: 8, multiplier: 20, count: 4, lv: 0.0001296296296296296 },
    { image: 8, multiplier: 40, count: 5, lv: 0.0000648148148148148 },
    { image: 9, multiplier: 5, count: 3, lv: 0.0005185185185185184 },
    { image: 9, multiplier: 10, count: 4, lv: 0.0002592592592592592 },
    { image: 9, multiplier: 20, count: 5, lv: 0.0001296296296296296 },
    { image: 10, multiplier: 100, count: 3, lv: 0.00002592592592592592 },
    { image: 10, multiplier: 500, count: 4, lv: 0.000005185185185185185 },
    {
      image: 10,
      multiplier: 1000,
      count: 5,
      lv: 0.0000025925925925925925
    }
  ]
  
  
  // let total = 0;
  // for(let i = 0; i< multiplierSuccessLines.length; i++){
  //   total += multiplierSuccessLines[i].lv * multiplierSuccessLines[i].multiplier;
  // }
  // console.log(total*9)

